/*项目所有请求接口*/
import Vue from 'vue';

class MyInterface {
    constructor(){
        this.vue=new Vue({});
    }
    getSwipeData(){
        /*获取轮播图数据*/
        return new Promise((resolve,reject)=>{
            this.vue.$http.get('api/getlunbo').then(result=>{
                resolve(result.body.message);
            },reject);
        });
    }
    getSixthData(){
        /*获取六宫格区域数据*/
        return new Promise((resolve,reject)=>{
            var data={state:200,list:[
                    {id:1,imgUrl:'public/images/home/menu1.png',text:'新闻资讯',to:'/home/newslist'},
                    {id:2,imgUrl:'public/images/home/menu2.png',text:'图片分享',to:'/home/photolist'},
                    {id:3,imgUrl:'public/images/home/menu3.png',text:'商品购买',to:'/home/goodslist'},
                    {id:4,imgUrl:'public/images/home/menu4.png',text:'留言反馈',to:''},
                    {id:5,imgUrl:'public/images/home/menu5.png',text:'视频专区',to:''},
                    {id:6,imgUrl:'public/images/home/menu6.png',text:'联系我们',to:''}
                ]};
            resolve(data);
        });
    }
    getNewsList(){
        /*获取新闻列表数据*/
        return new Promise((resolve,reject)=>{
            this.vue.$http.get('api/getnewslist').then(result=>{
                resolve(result.body.message);
            },reject);
        });
    }
    getNewsInfo(id){
        /*获取新闻详情数据*/
        return new Promise((resolve,reject)=>{
            this.vue.$http.get('api/getnew/'+id).then(result=>{
                resolve(result.body.message[0]);
            },reject);
        });
    }
    getComments(id,page){
        return new Promise((resolve, reject) =>{
            this.vue.$http.get(`api/getcomments/${id}?pageindex=${page}`).then(result=>{
                resolve(result.body.message);
            },reject);
        });
    }
    addComment(object){
        /*发表评论*/
        return new Promise((resolve, reject) => {
            this.vue.$http.post(`api/postcomment/${object.id}`,object).then(result=>{
                resolve();
            },reject)
        })
    }
    getAllCategory(){
        /*获取所有的图片分类*/
        return new Promise((resolve, reject) => {
            this.vue.$http.get('api/getimgcategory').then(result=>{
                resolve(result.body.message);
            },reject)
        })
    }
    getImages(id){
        /*获取图片列表数据*/
        return new Promise((resolve, reject) => {
            this.vue.$http.get(`api/getimages/${id}`).then(result=>{
                resolve(result.body.message);
            },reject)
        })
    }
    getPohtoInfo(id){
        /*获取图片详情*/
        return new Promise((resolve, reject) => {
            this.vue.$http.get(`api/getimageInfo/${id}`).then(result=>{
                resolve(result.body.message[0]);
            },reject)
        })
    }
    getImgList(id){
        /*获取图片分享详情中的缩略图数组,商品详情中的轮播图的API和缩略图公用一个*/
        return new Promise((resolve, reject) => {
            this.vue.$http.get(`api/getthumimages/${id}`).then(result=>{
                resolve(result.body.message);
            },reject)
        })
    }
    getGoods(pageindex=1){
        /*获取商品列表数据*/
        return new Promise((resolve, reject) => {
            this.vue.$http.get(`api/getgoods?pageindex=${pageindex}`).then(result=>{
                resolve(result.body.message);
            },reject)
        })
    }
    getGoodsInfo(id){
        /*获取商品参数区和价格,标题等数据*/
        return new Promise((resolve, reject) => {
            this.vue.$http.get(`api/goods/getinfo/${id}`).then(result=>{
                resolve(result.body.message[0]);
            },reject)
        })
    }
    getGoodsDesc(id){
        /*获取商品的图文介绍*/
        return new Promise((resolve, reject) => {
            this.vue.$http.get(`api/goods/getdesc/${id}`).then(result=>{
                resolve(result.body.message[0]);
            },reject)
        })
    }
    getShopCarList(ids){
        /*获取购物车页面数据 www.liulongbin.top:3005/api/goods/getshopcarlist/87,88,89*/
        return new Promise((resolve, reject) => {
            this.vue.$http.get(`api/goods/getshopcarlist/${ids.toString()}`).then(result=>{
                resolve(result.body.message);
            },reject)
        })
    }
}
export default new MyInterface;